package com.fly.toolbox;

import com.fly.toolbox.component.AppNotifier;
import com.fly.toolbox.config.ApplicationProperties;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.Objects;

public class AddFileAction extends AnAction {
    private final ApplicationProperties properties = ApplicationProperties.getInstance();

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {

        boolean addFile = false;
        VirtualFile[] virtualFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
        if (virtualFiles != null) {
            for (VirtualFile file : virtualFiles) {
                if (new File(file.getPath()).isFile()) {
                    properties.addFile(Objects.requireNonNull(e.getProject()).getBasePath(), file);
                    addFile = true;
                }
            }
        }
        if (addFile) {
            AppNotifier.notifyInfo("成功添加文件！");
        }
    }

}
